import router from ".";
import { useUserStore } from "@/store/auth";
// 导航前置守卫
router.beforeEach((to) => {
    const UserStore = useUserStore()
    const token = UserStore.token
    console.log(token, to.path)
    if (!token) {
        if (to.path !== '/login') {
            return { path: '/login' }
        }
    } else {
        if (to.path === '/login') {
            return { path: '/' }
        }
        // 权限列表校验 判断是否有交集
        if (to.meta?.needAuth && !UserStore.roles.some((role: string) => (to.meta.needAuth as string[]).includes(role))) {
            // 判断如果没有权限，重定向到首页
            return { path: '/' }
        }
    }
})